package com.mc2.docapp.disabilityassessmenttool.SpinalAffection;

import io.realm.RealmObject;
import io.realm.annotations.PrimaryKey;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class C_Scoliosis_Component extends RealmObject {
    @PrimaryKey
    public int id;
    private C_spin_affn_scoliosis_ext_points sc_extra_points = new C_spin_affn_scoliosis_ext_points();
    private C_spin_affnScolext sc_more_extra_points = new C_spin_affnScolext();
    private C_spin_affn_scoliosis_inner scoliosis_inner =  new C_spin_affn_scoliosis_inner();
    private double subTotalScoliosis = 0;
    private double totalScoliosis = 0;

    public void calc (C_Scoliosis_Component c_scoliosis_component) {
        double a = c_scoliosis_component.getScoliosis_inner().getScoliosisValue();
        double b = c_scoliosis_component.getSc_extra_points().getExtra_points();
        //TODO: Need to check to this
        double c = c_scoliosis_component.getSc_more_extra_points().getTorsoImbalance();
        double d = c_scoliosis_component.getSc_more_extra_points().getPain();

        double step1;
        double step2;
        double step3;
        double step4;

        step1 = calByFormula(a,b);
        step2 = calByFormula(step1,c);

        c_scoliosis_component.setSubTotalScoliosis(step2);

        c_scoliosis_component.setTotalScoliosis(d + step2);
    }

    private double calByFormula(double a, double b) {
        if(a<b){
            a = a + b;
            b = a - b;
            a = a - b;
        }
        double c = a + (((90 - a) * b) / 90.0);
        return c;
    }

    public C_Scoliosis_Component strip(C_Scoliosis_Component dt) {
        return new C_Scoliosis_Component(dt.getId(), dt.getSc_extra_points(),dt.getSc_more_extra_points(),
                dt.getScoliosis_inner(),dt.getSubTotalScoliosis(), getTotalScoliosis());
    }

}
